package zj.boxuegu.administrator.myapplication.Fragment;

import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import zj.boxuegu.administrator.myapplication.Activity.LoginActivity;
import zj.boxuegu.administrator.myapplication.Activity.ZhuCeActivity;
import zj.boxuegu.administrator.myapplication.R;

/**
 * Created by Administrator on 2018/4/2.
 */

public class MyFragment extends Fragment {
ImageView imageView;

    TextView textView;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view =inflater.inflate(R.layout.fragment_my,container ,false);

        imageView =view.findViewById(R.id.img1);
        textView =view.findViewById(R.id.text7);

        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {


                SharedPreferences sp = getActivity().getSharedPreferences("login", Context.MODE_PRIVATE);//不让别的进程读到
                boolean islogin = sp.getBoolean("islogin", false);
               /// String Username = sp.getString("mUsername", " ");
               // textView.setText(Username);

                if (islogin) {
                   // textView.setText(Username);
                    Toast.makeText(getActivity(), "已经登录过了", Toast.LENGTH_LONG).show();
                } else {

                    Intent intent = new Intent(getActivity(), LoginActivity.class);
                      startActivity(intent);
                }
            }
        });

        return  view;
    }


    @Override
    public void onResume() {
        SharedPreferences sp=getActivity().getSharedPreferences("login", Context.MODE_PRIVATE);//不让别的进程读到
        String   Username=sp.getString("mUsername","点击登录");
        textView.setText(Username);
        super.onResume();
    }
}
